package com.atguigu.gmall.config;

import com.atguigu.gmall.filter.TraceIdContextFilter;
import com.atguigu.gmall.hystrix.TraceStrategy;
import com.netflix.hystrix.strategy.HystrixPlugins;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author Jerry.Su
 * @Date 2022/2/21 9:39
 */
@Configuration
public class MyConfig {

    /**
     * 指定hystrix策略
     */
    @PostConstruct
    public void hystrixInit() {
        HystrixPlugins.getInstance().registerConcurrencyStrategy(new TraceStrategy());
    }

    @Bean
    public FilterRegistrationBean<TraceIdContextFilter> filterRegistrationBean() {
        FilterRegistrationBean<TraceIdContextFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new TraceIdContextFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }
}
